package com.igeek.clud_system.service;

import com.igeek.clud_system.common.Const;
import com.igeek.clud_system.dao.*;
import com.igeek.clud_system.entity.*;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PersonalCenterService {
    @Autowired
    ActivityDao activityDao;
    @Autowired
    ClubDao clubDao;
    @Autowired
    StudentDao studentDao;
    @Autowired
    ClubMemberDao clubMemberDao;
    @Autowired
    HttpSession session;
    @Autowired
    CommentDao commentDao;
    @Autowired
    ActivityAttendDao activityAttendDao;

    /**
     * 查询登录人的社团
     * @return
     */
    @Transactional
    public List<Club> myClub(){
        List<Club> list = new ArrayList<>();
        Student student = (Student) session.getAttribute(Const.LOGIN_USER);
        if (student != null){
            //查询社团成员表
            List<ClubMembers> member = clubMemberDao.findClubMemberByStudentId(student.getStudentId());
            for (ClubMembers clubMembers : member) {
                Club club = clubDao.findClubById(clubMembers.getClubId());
                list.add(club);
            }
            return list;
        }else {
            return null;
        }
    }

    /**
     *  查询登录人的活动
     * @return
     */
    @Transactional
    public List<Activity> myActivity(){
        List<Activity> list = new ArrayList<>();
        Student student = (Student) session.getAttribute(Const.LOGIN_USER);
        if (student != null){
            //查询社团成员表
            List<ActivityAttend> activityAttend = activityAttendDao.findByStudentId(student.getStudentId());
            for (ActivityAttend activityAttend1 : activityAttend) {
                Activity activity = activityDao.findById(activityAttend1.getActivityId());
                list.add(activity);
            }
            return list;
        }else {
            return null;
        }
    }

    /**
     *  更新活动参与状态（签到）
     * @param activityAttend
     */
    @Transactional
    public void updateActivityAttend(ActivityAttend activityAttend){
        activityAttendDao.updateActivityAttend(activityAttend);
    }

    /**
     *  获取活动签到码
     * @param activityId
     * @return
     */
    @Transactional
    public Activity getVerificationCode(Integer activityId){

        Activity activity = activityDao.findById(activityId);
        return activity;
    }
}
